# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

# Old Maintainer: Felix Yan <felixonmars@archlinux.org>
# Old Contributor: Andrea Scarpino <andrea@archlinux.org>
# Old Contributor: Yichao Yu <yyc1992@gmail.com>
# Old Contributor: Douglas Soares de Andrade <douglas@archlinux.org>
# Old Contributor: riai <riai@bigfoot.com> Ben <ben@benmazer.net>

pkgbase=python2-pyqt5
pkgname=('pyqt5-common' 'python2-pyqt5')
_pkgname=PyQt5
pkgver=5.15.4
pkgrel=3
arch=('x86_64' 'aarch64')
url='https://pypi.org/project/PyQt5/'
license=('GPL3')
makedepends=('sip4' 'python2-sip-pyqt5' 'sip' 'python2-opengl' 'python2-enum34'
             'python-dbus' 'qt5-connectivity' 'qt5-multimedia' 'qt5-tools'
             'qt5-serialport' 'qt5-svg' 'qt5-webkit' 'qt5-websockets'
             'qt5-x11extras' 'qt5-networkauth' 'qt5-xmlpatterns'
             'qt5-remoteobjects' 'python2-dbus')
source=("https://files.pythonhosted.org/packages/source/${_pkgname::1}/$_pkgname/PyQt5-$pkgver.tar.gz")
sha512sums=('6d19f549a71eb8df8ba8407398ccd6e3d339436f4f2e7c5dca6885849d6ce510c4f4dea3c97257685aa462bb09a2ead33d80234ccb934f9b1a40285dbec631c7')

build() {
  cd "$_pkgname-$pkgver"

  python2 configure.py --confirm-license --sip=/usr/bin/sip --no-sip-files \
    --qsci-api

  make
}

package_pyqt5-common(){
  pkgdesc="Common PyQt files shared between python-pyqt5 and python2-pyqt5"
  depends=('qt5-base')

  cd "$_pkgname-$pkgver"

  install -d "$pkgdir/usr/share/sip/PyQt5"

  install -Dm 644 PyQt5.api "$pkgdir/usr/share/qt/qsci/api/python/PyQt5.api"
  cp -a sip/* "$pkgdir"/usr/share/sip/PyQt5
}

package_python2-pyqt5(){
  pkgdesc="A set of Python 2.x bindings for the Qt5 toolkit"
  depends=('python2-sip-pyqt5' 'python2-enum34')
  optdepends=('python2-opengl: enable OpenGL 3D graphics in PyQt applications'
              'python2-dbus: for python-dbus mainloop support'
              'qt5-multimedia: QtMultimedia, QtMultimediaWidgets'
              'qt5-tools: QtHelp, QtDesigner'
              'qt5-svg: QtSvg'
              'qt5-webkit: QtWebKit, QtWebKitWidgets'
              'qt5-xmlpatterns: QtXmlPatterns'
              'qt5-declarative: QtQml, qmlplugin'
              'qt5-serialport: QtSerialPort'
              'qt5-websockets: QtWebSockets'
              'qt5-connectivity: QtNfc, QtBluetooth'
              'qt5-x11extras: QtX11Extras'
              'qt5-networkauth: QtNetworkAuth'
              'qt5-remoteobjects: QtRemoteObjects')

  cd "$_pkgname-$pkgver"

  # INSTALL_ROOT is needed for the QtDesigner module, the other Makefiles use
  # DESTDIR
  make DESTDIR="$pkgdir" INSTALL_ROOT="$pkgdir" install -j1

  # Remove unused py3 version of uic modules:
  rm -rf "$pkgdir"/usr/lib/python*/site-packages/PyQt5/uic/port_v3

  # compile Python bytecode
  python2 -m compileall -d / "$pkgdir/usr/lib"
  python2 -O -m compileall -d / "$pkgdir/usr/lib"

  # Fix conflicts with python-pyqt5
  mv "$pkgdir"/usr/bin/{,python2-}pyuic5
  mv "$pkgdir"/usr/bin/{,python2-}pylupdate5
  mv "$pkgdir"/usr/bin/{,python2-}pyrcc5

  rm -f "$pkgdir"/usr/lib/qt/plugins/designer/libpyqt5.so
  rm -f "$pkgdir"/usr/lib/qt/plugins/PyQt5/libpyqt5qmlplugin.so
  rm -f "$pkgdir"/usr/share/qt/qsci/api/python/PyQt5.api
}

